package bg.unisofia.fmi.tis.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name="t_thesis")
public class Thesis extends Identity {
	
	private String title = "";
	private String annotation = "";
	private String tasks = ""; //It should be no longer then 500 characters
	private String usedTechnologies = "";
	private Integer executionTime = 10; //It should be no longer then 70 days)
	private Date proposedOn;
	private String consultant = "";
	
	private String graduationDate;
	private String department;
	private String faculty;
	
	private Date reviewDate;
	private User reviewer;
	private String review;
	private Integer assessment;
	
	private User student;
	private User supervisor;
	private ThesisStatus status; // (accepted or rejected)
	
	private List<Comment> comments = new ArrayList<Comment>();

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getAnnotation() {
		return annotation;
	}

	public void setAnnotation(String annotation) {
		this.annotation = annotation;
	}

	@Column(length=500)
	public String getTasks() {
		return tasks;
	}

	public void setTasks(String tasks) {
		this.tasks = tasks;
	}

	public String getUsedTechnologies() {
		return usedTechnologies;
	}

	public void setUsedTechnologies(String usedTechnologies) {
		this.usedTechnologies = usedTechnologies;
	}

	public Integer getExecutionTime() {
		return executionTime;
	}

	public void setExecutionTime(Integer executionTime) {
		this.executionTime = executionTime;
	}

	public Date getProposedOn() {
		return proposedOn;
	}

	public void setProposedOn(Date proposedOn) {
		this.proposedOn = proposedOn;
	}

	public String getConsultant() {
		return consultant;
	}

	public void setConsultant(String consultant) {
		this.consultant = consultant;
	}

	@ManyToOne
	@JoinColumn(name="student_id")
	public User getStudent() {
		return student;
	}

	public void setStudent(User student) {
		this.student = student;
	}

	@ManyToOne
	@JoinColumn(name="supervisor_id")	
	public User getSupervisor() {
		return supervisor;
	}

	public void setSupervisor(User supervisor) {
		this.supervisor = supervisor;
	}

	public ThesisStatus getStatus() {
		return status;
	}

	public void setStatus(ThesisStatus status) {
		this.status = status;
	}

	@OneToMany(cascade=CascadeType.ALL, mappedBy="thesis")
	public List<Comment> getComments() {
		return comments;
	}

	public void setComments(List<Comment> comments) {
		this.comments = comments;
	}
	
	@Transient
	public String getLastComment() {
		if (getComments().size() > 0) {
			Comment comment = getComments().get(getComments().size() - 1);
			return comment.getProfessor().getName() + ": " + 
				comment.getContent() + " // " + comment.getSubmittedOn();
		}
		return "";
	}

	public String getGraduationDate() {
		return graduationDate;
	}

	public void setGraduationDate(String graduationDate) {
		this.graduationDate = graduationDate;
	}

	public String getDepartment() {
		return department;
	}

	public void setDepartment(String department) {
		this.department = department;
	}

	public String getFaculty() {
		return faculty;
	}

	public void setFaculty(String faculty) {
		this.faculty = faculty;
	}

	public Date getReviewDate() {
		return reviewDate;
	}

	public void setReviewDate(Date reviewDate) {
		this.reviewDate = reviewDate;
	}
	
	@ManyToOne
	@JoinColumn(name="reviewer_id")
	public User getReviewer() {
		return reviewer;
	}

	public void setReviewer(User reviewer) {
		this.reviewer = reviewer;
	}

	public String getReview() {
		return review;
	}

	public void setReview(String review) {
		this.review = review;
	}

	public Integer getAssessment() {
		return assessment;
	}

	public void setAssessment(Integer assessment) {
		this.assessment = assessment;
	}
}
